<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::BN - openssl: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Comparable</span>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-generate_prime">::generate_prime</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-rand">::rand</a>
    <li ><a href="#method-c-rand_range">::rand_range</a>
    <li ><a href="#method-i-25">#%</a>
    <li ><a href="#method-i-2A">#*</a>
    <li ><a href="#method-i-2A-2A">#**</a>
    <li ><a href="#method-i-2B">#+</a>
    <li ><a href="#method-i-2B-40">#+@</a>
    <li ><a href="#method-i-2D">#-</a>
    <li ><a href="#method-i-2D-40">#-@</a>
    <li ><a href="#method-i-2F">#/</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-3D-3D-3D">#===</a>
    <li ><a href="#method-i-3E-3E">#&gt;&gt;</a>
    <li ><a href="#method-i-abs">#abs</a>
    <li ><a href="#method-i-bit_set-3F">#bit_set?</a>
    <li ><a href="#method-i-clear_bit-21">#clear_bit!</a>
    <li ><a href="#method-i-cmp">#cmp</a>
    <li ><a href="#method-i-coerce">#coerce</a>
    <li ><a href="#method-i-copy">#copy</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-gcd">#gcd</a>
    <li ><a href="#method-i-get_flags">#get_flags</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-lshift-21">#lshift!</a>
    <li ><a href="#method-i-mod_add">#mod_add</a>
    <li ><a href="#method-i-mod_exp">#mod_exp</a>
    <li ><a href="#method-i-mod_inverse">#mod_inverse</a>
    <li ><a href="#method-i-mod_mul">#mod_mul</a>
    <li ><a href="#method-i-mod_sqr">#mod_sqr</a>
    <li ><a href="#method-i-mod_sqrt">#mod_sqrt</a>
    <li ><a href="#method-i-mod_sub">#mod_sub</a>
    <li ><a href="#method-i-negative-3F">#negative?</a>
    <li ><a href="#method-i-num_bits">#num_bits</a>
    <li ><a href="#method-i-num_bytes">#num_bytes</a>
    <li ><a href="#method-i-odd-3F">#odd?</a>
    <li ><a href="#method-i-one-3F">#one?</a>
    <li ><a href="#method-i-pretty_print">#pretty_print</a>
    <li ><a href="#method-i-prime-3F">#prime?</a>
    <li ><a href="#method-i-prime_fasttest-3F">#prime_fasttest?</a>
    <li ><a href="#method-i-rshift-21">#rshift!</a>
    <li ><a href="#method-i-set_bit-21">#set_bit!</a>
    <li ><a href="#method-i-set_flags">#set_flags</a>
    <li ><a href="#method-i-sqr">#sqr</a>
    <li ><a href="#method-i-to_bn">#to_bn</a>
    <li ><a href="#method-i-to_i">#to_i</a>
    <li ><a href="#method-i-to_int">#to_int</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-ucmp">#ucmp</a>
    <li ><a href="#method-i-zero-3F">#zero?</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::BN">
    <h1 id="class-OpenSSL::BN" class="class">
      class OpenSSL::BN
    </h1>

    <section class="description">
    
    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="CONSTTIME">CONSTTIME
          <dd>
          <dt id="MALLOCED">MALLOCED
          <dd>
          <dt id="STATIC_DATA">STATIC_DATA
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-generate_prime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          generate_prime(bits, [, safe [, add [, rem]]]) &rarr; bn
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates a random prime number of bit length <em>bits</em>. If <em>safe</em> is set to <code>true</code>, generates a safe prime. If <em>add</em> is specified, generates a prime that fulfills condition <code>p % add = rem</code>.</p>

<h3 id="method-c-generate_prime-label-Parameters">Parameters<span><a href="#method-c-generate_prime-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><em>bits</em> - integer</p>
</li><li>
<p><em>safe</em> - boolean</p>
</li><li>
<p><em>add</em> - <a href="BN.html"><code>BN</code></a></p>
</li><li>
<p><em>rem</em> - <a href="BN.html"><code>BN</code></a></p>
</li></ul>

                              <div class="method-source-code" id="generate_prime-source">
            <pre>static VALUE
ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
{
    BIGNUM *add = NULL, *rem = NULL, *result;
    int safe = 1, num;
    VALUE vnum, vsafe, vadd, vrem, obj;

    rb_scan_args(argc, argv, &quot;13&quot;, &amp;vnum, &amp;vsafe, &amp;vadd, &amp;vrem);

    num = NUM2INT(vnum);

    if (vsafe == Qfalse) {
        safe = 0;
    }
    if (!NIL_P(vadd)) {
        add = GetBNPtr(vadd);
        rem = NIL_P(vrem) ? NULL : GetBNPtr(vrem);
    }
    obj = NewBN(klass);
    if (!(result = BN_new())) {
        ossl_raise(eBNError, NULL);
    }
    if (!BN_generate_prime_ex(result, num, safe, add, rem, NULL)) {
        BN_free(result);
        ossl_raise(eBNError, NULL);
    }
    SetBN(obj, result);

    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::BN.new(bn) &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::BN.new(integer) &rarr; aBN
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::BN.new(string, base = 10) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Construct a new OpenSSL BIGNUM object.</p>

<p>If <code>bn</code> is an <a href="../Integer.html"><code>Integer</code></a> or <a href="BN.html"><code>OpenSSL::BN</code></a>, a new instance of <a href="BN.html"><code>OpenSSL::BN</code></a> representing the same value is returned. See also <a href="../Integer.html#method-i-to_bn"><code>Integer#to_bn</code></a> for the short-hand.</p>

<p>If a String is given, the content will be parsed according to <code>base</code>.</p>
<dl class="rdoc-list note-list"><dt><code>string</code>
<dd>
<p>The string to be parsed.</p>
</dd><dt><code>base</code>
<dd>
<p>The format. Must be one of the following:</p>
<ul><li>
<p><code>0</code>  - MPI format. See the man page BN_mpi2bn(3) for details.</p>
</li><li>
<p><code>2</code>  - Variable-length and big-endian binary encoding of a positive number.</p>
</li><li>
<p><code>10</code> - Decimal number representation, with a leading ‘-’ for a negative number.</p>
</li><li>
<p><code>16</code> - Hexadeciaml number representation, with a leading ‘-’ for a negative number.</p>
</li></ul>
</dd></dl>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
{
    BIGNUM *bn;
    VALUE str, bs;
    int base = 10;
    char *ptr;

    if (rb_scan_args(argc, argv, &quot;11&quot;, &amp;str, &amp;bs) == 2) {
        base = NUM2INT(bs);
    }

    if (NIL_P(str)) {
        ossl_raise(rb_eArgError, &quot;invalid argument&quot;);
    }

    if (RB_INTEGER_TYPE_P(str)) {
        GetBN(self, bn);
        integer_to_bnptr(str, bn);

        return self;
    }

    if (RTEST(rb_obj_is_kind_of(str, cBN))) {
        BIGNUM *other;

        GetBN(self, bn);
        GetBN(str, other); /* Safe - we checked kind_of? above */
        if (!BN_copy(bn, other)) {
            ossl_raise(eBNError, NULL);
        }
        return self;
    }

    GetBN(self, bn);
    switch (base) {
    case 0:
        ptr = StringValuePtr(str);
        if (!BN_mpi2bn((unsigned char *)ptr, RSTRING_LENINT(str), bn)) {
            ossl_raise(eBNError, NULL);
        }
        break;
    case 2:
        ptr = StringValuePtr(str);
        if (!BN_bin2bn((unsigned char *)ptr, RSTRING_LENINT(str), bn)) {
            ossl_raise(eBNError, NULL);
        }
        break;
    case 10:
        if (!BN_dec2bn(&amp;bn, StringValueCStr(str))) {
            ossl_raise(eBNError, NULL);
        }
        break;
    case 16:
        if (!BN_hex2bn(&amp;bn, StringValueCStr(str))) {
            ossl_raise(eBNError, NULL);
        }
        break;
    default:
        ossl_raise(rb_eArgError, &quot;invalid radix %d&quot;, base);
    }
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rand" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rand(bits [, fill [, odd]]) &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates a cryptographically strong pseudo-random number of <code>bits</code>.</p>

<p>See also the man page BN_rand(3).</p>

                              <div class="method-source-code" id="rand-source">
            <pre>static VALUE
ossl_bn_s_rand(int argc, VALUE *argv, VALUE klass)
{
    BIGNUM *result;
    int bottom = 0, top = 0, b;
    VALUE bits, fill, odd, obj;

    switch (rb_scan_args(argc, argv, &quot;12&quot;, &amp;bits, &amp;fill, &amp;odd)) {
      case 3:
        bottom = (odd == Qtrue) ? 1 : 0;
        /* FALLTHROUGH */
      case 2:
        top = NUM2INT(fill);
    }
    b = NUM2INT(bits);
    obj = NewBN(klass);
    if (!(result = BN_new())) {
        ossl_raise(eBNError, &quot;BN_new&quot;);
    }
    if (BN_rand(result, b, top, bottom) &lt;= 0) {
        BN_free(result);
        ossl_raise(eBNError, &quot;BN_rand&quot;);
    }
    SetBN(obj, result);
    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rand_range" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rand_range(range) &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates a cryptographically strong pseudo-random number in the range 0…<code>range</code>.</p>

<p>See also the man page BN_rand_range(3).</p>

                              <div class="method-source-code" id="rand_range-source">
            <pre>static VALUE
ossl_bn_s_rand_range(VALUE klass, VALUE range)
{
    BIGNUM *bn = GetBNPtr(range), *result;
    VALUE obj = NewBN(klass);
    if (!(result = BN_new()))
        ossl_raise(eBNError, &quot;BN_new&quot;);
    if (BN_rand_range(result, bn) &lt;= 0) {
        BN_free(result);
        ossl_raise(eBNError, &quot;BN_rand_range&quot;);
    }
    SetBN(obj, result);
    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-25" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn % bn2 &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-2A" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn * bn2 &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-2A-2A" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn ** bn2 &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-2B" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn + bn2 &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-2B-40" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          +bn &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="2B-40-source">
            <pre>static VALUE
ossl_bn_uplus(VALUE self)
{
    VALUE obj;
    BIGNUM *bn1, *bn2;

    GetBN(self, bn1);
    obj = NewBN(cBN);
    bn2 = BN_dup(bn1);
    if (!bn2)
        ossl_raise(eBNError, &quot;BN_dup&quot;);
    SetBN(obj, bn2);

    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn - bn2 &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-2D-40" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          -bn &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="2D-40-source">
            <pre>static VALUE
ossl_bn_uminus(VALUE self)
{
    VALUE obj;
    BIGNUM *bn1, *bn2;

    GetBN(self, bn1);
    obj = NewBN(cBN);
    bn2 = BN_dup(bn1);
    if (!bn2)
        ossl_raise(eBNError, &quot;BN_dup&quot;);
    SetBN(obj, bn2);
    BN_set_negative(bn2, !BN_is_negative(bn2));

    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn1 / bn2 &rarr; [result, remainder]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Division of <a href="BN.html"><code>OpenSSL::BN</code></a> instances</p>

                              <div class="method-source-code" id="2F-source">
            <pre>static VALUE
ossl_bn_div(VALUE self, VALUE other)
{
    BIGNUM *bn1, *bn2 = GetBNPtr(other), *r1, *r2;
    VALUE klass, obj1, obj2;

    GetBN(self, bn1);

    klass = rb_obj_class(self);
    obj1 = NewBN(klass);
    obj2 = NewBN(klass);
    if (!(r1 = BN_new())) {
        ossl_raise(eBNError, NULL);
    }
    if (!(r2 = BN_new())) {
        BN_free(r1);
        ossl_raise(eBNError, NULL);
    }
    if (!BN_div(r1, r2, bn1, bn2, ossl_bn_ctx)) {
        BN_free(r1);
        BN_free(r2);
        ossl_raise(eBNError, NULL);
    }
    SetBN(obj1, r1);
    SetBN(obj2, r2);

    return rb_ary_new3(2, obj1, obj2);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3C-3C" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn &lt;&lt; bits &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-3C-3D-3E" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">&lt;=&gt;</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="BN.html#method-i-cmp">cmp</a>
                            </div>
                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn == obj &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> only if <em>obj</em> has the same value as <em>bn</em>. Contrast this with <a href="BN.html#method-i-eql-3F"><code>OpenSSL::BN#eql?</code></a>, which requires obj to be <a href="BN.html"><code>OpenSSL::BN</code></a>.</p>

                              <div class="method-source-code" id="3D-3D-source">
            <pre>static VALUE
ossl_bn_eq(VALUE self, VALUE other)
{
    BIGNUM *bn1, *bn2;

    GetBN(self, bn1);
    other = try_convert_to_bn(other);
    if (NIL_P(other))
        return Qfalse;
    GetBN(other, bn2);

    if (!BN_cmp(bn1, bn2)) {
        return Qtrue;
    }
    return Qfalse;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="BN.html#method-i-3D-3D-3D">===</a>
                            </div>

                          </div>

                  <div id="method-i-3D-3D-3D" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">===</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> only if <em>obj</em> has the same value as <em>bn</em>. Contrast this with <a href="BN.html#method-i-eql-3F"><code>OpenSSL::BN#eql?</code></a>, which requires obj to be <a href="BN.html"><code>OpenSSL::BN</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="BN.html#method-i-3D-3D">==</a>
                            </div>
                          </div>

                  <div id="method-i-3E-3E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bn &gt;&gt; bits &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-abs" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          abs &rarr; aBN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="abs-source">
            <pre>static VALUE
ossl_bn_abs(VALUE self)
{
    BIGNUM *bn1;

    GetBN(self, bn1);
    if (BN_is_negative(bn1)) {
        return ossl_bn_uminus(self);
    }
    else {
        return ossl_bn_uplus(self);
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-bit_set-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          bit_set?(bit) &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Tests bit <em>bit</em> in <em>bn</em> and returns <code>true</code> if set, <code>false</code> if not set.</p>

                              <div class="method-source-code" id="bit_set-3F-source">
            <pre>static VALUE
ossl_bn_is_bit_set(VALUE self, VALUE bit)
{
    int b;
    BIGNUM *bn;

    b = NUM2INT(bit);
    GetBN(self, bn);
    if (BN_is_bit_set(bn, b)) {
        return Qtrue;
    }
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-clear_bit-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          clear_bit!(bit) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-cmp" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp(bn2) &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="BN.html#method-i-3C-3D-3E">&lt;=&gt;</a>
                            </div>

                          </div>

                  <div id="method-i-coerce" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">coerce</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="coerce-source">
            <pre>static VALUE
ossl_bn_coerce(VALUE self, VALUE other)
{
    switch(TYPE(other)) {
    case T_STRING:
        self = ossl_bn_to_s(0, NULL, self);
        break;
    case T_FIXNUM:
    case T_BIGNUM:
        self = ossl_bn_to_i(self);
        break;
    default:
        if (!RTEST(rb_obj_is_kind_of(other, cBN))) {
            ossl_raise(rb_eTypeError, &quot;Don&#39;t know how to coerce&quot;);
        }
    }
    return rb_assoc_new(other, self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-copy" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">copy</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="BN.html#method-i-initialize_copy">initialize_copy</a>
                            </div>
                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(obj) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> only if <em>obj</em> is a <code>OpenSSL::BN</code> with the same value as <em>bn</em>. Contrast this with <a href="BN.html#method-i-3D-3D"><code>OpenSSL::BN#==</code></a>, which performs type conversions.</p>

                              <div class="method-source-code" id="eql-3F-source">
            <pre>static VALUE
ossl_bn_eql(VALUE self, VALUE other)
{
    BIGNUM *bn1, *bn2;

    if (!rb_obj_is_kind_of(other, cBN))
        return Qfalse;
    GetBN(self, bn1);
    GetBN(other, bn2);

    return BN_cmp(bn1, bn2) ? Qfalse : Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-gcd" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          gcd(bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-get_flags" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          get_flags(flags) &rarr; flags
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the flags on the <a href="BN.html"><code>BN</code></a> object. The argument is used as a bit mask.</p>

<h3 id="method-i-get_flags-label-Parameters">Parameters<span><a href="#method-i-get_flags-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><em>flags</em> - integer</p>
</li></ul>

                              <div class="method-source-code" id="get_flags-source">
            <pre>static VALUE
ossl_bn_get_flags(VALUE self, VALUE arg)
{
    BIGNUM *bn;
    GetBN(self, bn);

    return INT2NUM(BN_get_flags(bn, NUM2INT(arg)));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hash" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          hash &rarr; Integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash code for this object.</p>

<p>See also Object#hash.</p>

                              <div class="method-source-code" id="hash-source">
            <pre>static VALUE
ossl_bn_hash(VALUE self)
{
    BIGNUM *bn;
    VALUE tmp, hash;
    unsigned char *buf;
    int len;

    GetBN(self, bn);
    len = BN_num_bytes(bn);
    buf = ALLOCV(tmp, len);
    if (BN_bn2bin(bn, buf) != len) {
        ALLOCV_END(tmp);
        ossl_raise(eBNError, &quot;BN_bn2bin&quot;);
    }

    hash = ST2FIX(rb_memhash(buf, len));
    ALLOCV_END(tmp);

    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-initialize_copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">initialize_copy</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
ossl_bn_copy(VALUE self, VALUE other)
{
    BIGNUM *bn1, *bn2;

    rb_check_frozen(self);

    if (self == other) return self;

    GetBN(self, bn1);
    bn2 = GetBNPtr(other);

    if (!BN_copy(bn1, bn2)) {
        ossl_raise(eBNError, NULL);
    }
    return self;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="BN.html#method-i-copy">copy</a>
                            </div>

                          </div>

                  <div id="method-i-lshift-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lshift!(bits) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_add" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_add(bn1, bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_exp" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_exp(bn1, bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_inverse" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_inverse(bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_mul" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_mul(bn1, bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_sqr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_sqr(bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_sqrt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_sqrt(bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-mod_sub" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mod_sub(bn1, bn2) &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-negative-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          negative? &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="negative-3F-source">
            <pre>static VALUE
ossl_bn_is_negative(VALUE self)
{
    BIGNUM *bn;

    GetBN(self, bn);
    if (BN_is_zero(bn))
        return Qfalse;
    return BN_is_negative(bn) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-num_bits" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          num_bits &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-num_bytes" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          num_bytes &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-odd-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          odd? &rarr; true | false
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-one-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          one? &rarr; true | false
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-pretty_print" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pretty_print</span><span
                                class="method-args">(q)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="pretty_print-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/bn.rb, line 20</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">pretty_print</span>(<span class="ruby-identifier">q</span>)
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">object_group</span>(<span class="ruby-keyword">self</span>) {
    <span class="ruby-identifier">q</span>.<span class="ruby-identifier">text</span> <span class="ruby-string">&#39; &#39;</span>
    <span class="ruby-identifier">q</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">to_i</span>.<span class="ruby-identifier">to_s</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-prime-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          prime? &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          prime?(checks) &rarr; true | false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Performs a Miller-Rabin probabilistic primality test for <code>bn</code>.</p>

<p><strong><code>checks</code> parameter is deprecated in version 3.0.</strong> It has no effect.</p>

                              <div class="method-source-code" id="prime-3F-source">
            <pre>static VALUE
ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
{
    BIGNUM *bn;
    int ret;

    rb_check_arity(argc, 0, 1);
    GetBN(self, bn);

#ifdef HAVE_BN_CHECK_PRIME
    ret = BN_check_prime(bn, ossl_bn_ctx, NULL);
    if (ret &lt; 0)
        ossl_raise(eBNError, &quot;BN_check_prime&quot;);
#else
    ret = BN_is_prime_fasttest_ex(bn, BN_prime_checks, ossl_bn_ctx, 1, NULL);
    if (ret &lt; 0)
        ossl_raise(eBNError, &quot;BN_is_prime_fasttest_ex&quot;);
#endif
    return ret ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-prime_fasttest-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          prime_fasttest? &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          prime_fasttest?(checks) &rarr; true | false
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          prime_fasttest?(checks, trial_div) &rarr; true | false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Performs a Miller-Rabin probabilistic primality test for <code>bn</code>.</p>

<p><strong>Deprecated in version 3.0.</strong> Use <a href="BN.html#method-i-prime-3F"><code>prime?</code></a> instead.</p>

<p><code>checks</code> and <code>trial_div</code> parameters no longer have any effect.</p>

                              <div class="method-source-code" id="prime_fasttest-3F-source">
            <pre>static VALUE
ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
{
    rb_check_arity(argc, 0, 2);
    return ossl_bn_is_prime(0, argv, self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rshift-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rshift!(bits) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-set_bit-21" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_bit!(bit) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-set_flags" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_flags(flags) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Enables the flags on the <a href="BN.html"><code>BN</code></a> object. Currently, the flags argument can contain zero of <a href="BN.html#CONSTTIME"><code>OpenSSL::BN::CONSTTIME</code></a>.</p>

                              <div class="method-source-code" id="set_flags-source">
            <pre>static VALUE
ossl_bn_set_flags(VALUE self, VALUE arg)
{
    BIGNUM *bn;
    GetBN(self, bn);

    BN_set_flags(bn, NUM2INT(arg));
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sqr" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sqr &rarr; aBN
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-to_bn" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_bn</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="to_bn-source">
            <pre>static VALUE
ossl_bn_to_bn(VALUE self)
{
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_i" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_i &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="to_i-source">
            <pre>static VALUE
ossl_bn_to_i(VALUE self)
{
    BIGNUM *bn;
    char *txt;
    VALUE num;

    GetBN(self, bn);

    if (!(txt = BN_bn2hex(bn))) {
        ossl_raise(eBNError, NULL);
    }
    num = rb_cstr_to_inum(txt, 16, Qtrue);
    OPENSSL_free(txt);

    return num;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="BN.html#method-i-to_int">to_int</a>
                            </div>

                          </div>

                  <div id="method-i-to_int" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_int</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="BN.html#method-i-to_i">to_i</a>
                            </div>
                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s(base = 10) &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string representation of the bignum.</p>

<p><a href="BN.html#method-c-new"><code>BN.new</code></a> can parse the encoded string to convert back into an <a href="BN.html"><code>OpenSSL::BN</code></a>.</p>
<dl class="rdoc-list note-list"><dt><code>base</code>
<dd>
<p>The format. Must be one of the following:</p>
<ul><li>
<p><code>0</code>  - MPI format. See the man page BN_bn2mpi(3) for details.</p>
</li><li>
<p><code>2</code>  - Variable-length and big-endian binary encoding. The sign of the bignum is ignored.</p>
</li><li>
<p><code>10</code> - Decimal number representation, with a leading ‘-’ for a negative bignum.</p>
</li><li>
<p><code>16</code> - Hexadeciaml number representation, with a leading ‘-’ for a negative bignum.</p>
</li></ul>
</dd></dl>

                              <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
{
    BIGNUM *bn;
    VALUE str, bs;
    int base = 10, len;
    char *buf;

    if (rb_scan_args(argc, argv, &quot;01&quot;, &amp;bs) == 1) {
        base = NUM2INT(bs);
    }
    GetBN(self, bn);
    switch (base) {
    case 0:
        len = BN_bn2mpi(bn, NULL);
        str = rb_str_new(0, len);
        if (BN_bn2mpi(bn, (unsigned char *)RSTRING_PTR(str)) != len)
            ossl_raise(eBNError, NULL);
        break;
    case 2:
        len = BN_num_bytes(bn);
        str = rb_str_new(0, len);
        if (BN_bn2bin(bn, (unsigned char *)RSTRING_PTR(str)) != len)
            ossl_raise(eBNError, NULL);
        break;
    case 10:
        if (!(buf = BN_bn2dec(bn))) ossl_raise(eBNError, NULL);
        str = ossl_buf2str(buf, rb_long2int(strlen(buf)));
        break;
    case 16:
        if (!(buf = BN_bn2hex(bn))) ossl_raise(eBNError, NULL);
        str = ossl_buf2str(buf, rb_long2int(strlen(buf)));
        break;
    default:
        ossl_raise(rb_eArgError, &quot;invalid radix %d&quot;, base);
    }

    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ucmp" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ucmp(bn2) &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                  <div id="method-i-zero-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          zero? &rarr; true | false
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

